package world.controllers

import org.springframework.beans.factory.annotation.Autowired
import org.springframework.cache.annotation.Cacheable
import org.springframework.stereotype.Controller
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.ResponseBody
import org.springframework.web.bind.annotation.RestController

@Controller
@RequestMapping(value="/react")
class ReactController {

    @RequestMapping(value="/index")
    def index() {
        return "react/index"
    }

    @ResponseBody
    @RequestMapping(value="/plus")
    def plus(@RequestParam(name="num") Integer num) {
        return num + 1
    }

    @ResponseBody
    @RequestMapping(value="/minus")
    def minus(@RequestBody HashMap params) {
        return params.num - 1
    }

    @ResponseBody
    @RequestMapping(value="/random")
    def random() {
        return new Random().nextInt(100)
    }

    @ResponseBody
    @RequestMapping(value="/reset")
    def reset(@RequestBody HashMap params) {
        return params.num
    }

}
